package de.tabuma.pm.projectnavigation.controller;

import de.tabuma.pm.projectnavigation.logik.ProjectNavigationFacade;
import de.tabuma.pm.projectnavigation.entity.ProjectNavigation;
import de.tabuma.customer.logik.PMF;
import de.tabuma.lib.tabumacontroller;

import java.io.PrintWriter;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import de.tabuma.pm.*;
import de.tabuma.pm.logik.*;

/**
 *
 * @author alefen
 */
public class pncontent extends tabumacontroller {

    public pncontent(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

        if(request.getParameter(constants.ProjectNavigationContent)!=null) {

            request.setAttribute(constants.ProjectNavigationContent, request.getParameter(constants.ProjectNavigationContent));
            request.setAttribute(constants.ProjectNavigationId, request.getParameter(constants.ProjectNavigationId));

            String navContentId = request.getParameter(constants.ProjectNavigationContent);
            int navContentIdInt = Integer.valueOf(navContentId).intValue();

            if(navContentIdInt==0) {
                String navId = request.getParameter(constants.ProjectNavigationId);
                int navIdInt = Integer.valueOf(navId).intValue();
                ProjectNavigation pn = ProjectNavigationFacade.get(navIdInt);
                navContentIdInt = pn.getNavMode();
                request.setAttribute(constants.ProjectNavigationContent, ""+pn.getNavMode());
            }

            switch(navContentIdInt) {
                case constants.ProjectNavigationExternalContent:
                    Hashtable param1 = (Hashtable) this.getParameter().clone();
                    param1.put(constants.ProjectNavigationContent,""+constants.ProjectNavigationExternalContent);
                    param1.put(constants.ProjectNavigationId, navContentId);
                    de.tabuma.pm.externalcontent.controller.controller ecc = new de.tabuma.pm.externalcontent.controller.controller(this.getServlet(), param1);
                    ecc.navigate(context, request, response, out);
                    break;
                case constants.ProjectNavigationHtmlContent:
                    Hashtable param2 = (Hashtable) this.getParameter().clone();
                    param2.put(constants.ProjectNavigationContent,""+constants.ProjectNavigationHtmlContent);
                    param2.put(constants.ProjectNavigationId, navContentId);
                    de.tabuma.pm.htmlcontent.controller.controller hcc = new de.tabuma.pm.htmlcontent.controller.controller(this.getServlet(), param2);
                    hcc.navigate(context, request, response, out);
                    break;
            }

        }

    }

}
